<?php
/*
 * 手机客户端 秀场浏览作品评论接口
 * 传入参数 
 * 2013-12-28
 */
include "inc/public_header.php";

//用户信息处理函数
include "func/user.php";				

//构建返回值
$reJson = array();
 
$page			= $_REQUEST["page"]; 			//页数，第一页为0
$pagesize		= $_REQUEST["pagesize"];		//每页记录数
$worksid	    = $_REQUEST["worksid"];			//作品id	
//$hd_id			= $_REQUEST["hd_id"];			//活动主键

$uid = "";
//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if($uInfoArr){
	$uid = $uInfoArr["uid"];//用户信息主键
}


if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 20; //默认每页20条
}

$reJson["success"] = "1";

//获取评论总数
$sql = "select 
			count(a.id) as ct 
		from 
			new_weituo_comment a 
			left join new_weituo_person b on a.uid=b.uid 
			inner join user_base f on a.uid=f.uid
			inner join new_weituo_zuopin c on a.zpid=c.id
			
		where 
			a.dr='0' and  c.aflag='1' and c.dr='0' and a.zpid='".$worksid."'
			";
			
$db->query($sql);
$db->next_record();
$reJson["count"] = $db->f("ct");

//获取作品评论数据
$sql="
		select 
				 a.id
				,a.uid
				,a.comment
				,date_format(a.createtime,'%Y-%m-%d %H:%i') as ctime 
				,b.nickname
				,b.ilogo_path
				,c.aname
				,a.zpid
				,c.uid as zpuid
				,d.pingfen
				,f.mobile
		from new_weituo_comment a 
				left join new_weituo_person b on a.uid=b.uid 
				inner join user_base f on a.uid=f.uid
				inner join new_weituo_zuopin c on a.zpid=c.id
				left join new_weituo_pingfen d on d.zpid='".$worksid."' and a.uid=d.uid
		where 
				a.dr='0' 
				and c.dr='0' 
				and c.aflag='1' 
				and a.zpid='".$worksid."' order by a.createtime desc
";
$sql = $sql." limit ".($page * $pagesize).",".$pagesize;

$db->query($sql);
$plListArr = array();
while($db->next_record()){
	$pid=$db->f("id");
	$sql= "select count(id) as ct from new_weituo_huifu where dr='0' and pid='".$pid."'";
	$db1->query($sql);
	$db1->next_record();
	$replyCount = $db1->f("ct");
	$nickName = $db->f("nickname");
	if($nickName==null){
		$nickName = user_fix_mobile($db->f("mobile"));
	}
	if($db->f("pingfen")){
		$pingfen=$db->f("pingfen");
	}else{
		$pingfen = "0";	
	}
	if($uid==$db->f("uid")){
		$myself="1";
	}else{
		$myself="0";
	}
	$plListArr[] = array(
		"userName" =>$nickName					//评论人昵称
		,"commentContent"=>$db->f("comment")	//评论内容
		,"commentDate"=>$db->f("ctime")			//建立时间
		,"commentId"=>$db->f("id")				//评论id
		,"level"=>$pingfen						//评分
		,"replyCount" =>$replyCount				//回复数
		,"myself"=>$myself						//判断作品是否自己的
	);
}
$reJson["list"]= $plListArr;
echo json_encode($reJson);

?>

